import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
	state: {
		// 用户身份
		userType: uni.getStorageSync('userType') || '',
		tabIndex: uni.getStorageSync('tabIndex') || 0,
		contractInfo:{
			
		},
	},
	mutations: {
		// 保存用户身份
		setUserInfo(state, token) {
			uni.setStorageSync('userType', token)
			state.userType = token;
		},
		setTabIndex(state, data) {
			uni.setStorageSync('tabIndex', data)
			state.tabIndex = data;
		},
		setContractInfo(state,payload){
			let key
			if(Array.isArray(payload)){
				key = payload[0] ? payload[0].key : void(0)
				if(key){
					Object.defineProperty(state.contractInfo,key,{
						value:payload,
						configurable:true,
						writable:true,
						enumerable:true
					})
				}
			}else{
				key = payload.key
				Object.defineProperty(state.contractInfo,key,{
					value:payload,
					configurable:true,
					writable:true,
					enumerable:true
				})
			}
			console.log('vuex中保存的表单数据：',state.contractInfo);
		}
	},
})